<%-- 
    Document   : compte
    Created on : 2012-03-10, 11:08:14
    Author     : Étienne
--%>

<%@page import="application.beans.SectionBean"%>
<%@page import="java.util.List"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.HashMap"%>
<%@page import="java.util.ResourceBundle"%>
<%@page import="java.util.Locale"%>
<%@page import="application.beans.CoursBean"%>
<%@page import="application.beans.MessageInterneBean"%>
<%@page import="controleur.ConstantesWeb"%>
<%@page import="application.beans.CompteBean"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
    Locale currentLocale = Locale.FRENCH;
    ResourceBundle strings = ResourceBundle.getBundle("StringsBundle", currentLocale);
    
    List<SectionBean> sections = (List<SectionBean>)(session.getAttribute(ConstantesWeb.ATTRIBUT_LISTE_SECTIONS));
    pageContext.setAttribute(ConstantesWeb.ATTRIBUT_LISTE_SECTIONS, sections);
    
    // On va chercher le compte utilisateur, qu'il soit connecté ou non
    CompteBean utilisateur = (CompteBean)session.getAttribute(ConstantesWeb.ATTRIBUT_UTILISATEUR);
    pageContext.setAttribute(ConstantesWeb.ATTRIBUT_UTILISATEUR, utilisateur);
    // On va chercher le numéro de page
    Integer numPage = (Integer)session.getAttribute(ConstantesWeb.PARAM_NUM_PAGE);
    // On va chercher la liste des statuts
    HashMap<Integer,String> statuts = (HashMap<Integer,String>)session.getAttribute(ConstantesWeb.ATTRIBUT_STATUTS);
    
    String idBackground = (String)session.getAttribute(ConstantesWeb.ATTRIBUT_ID_BACKGROUND);
%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="CSS/styleCompte.css" type="text/css"/>
        <link rel="stylesheet" href="CSS/styleGeneral.css" type="text/css"/>
        <title>S.U.P.PORT: <%= strings.getString("monCompte") %></title>
        <script type="text/javascript" src="Scripts/jQuery.js"></script>
        <script type="text/javascript" src="Scripts/scriptsGeneraux.js"></script>
        <script type="text/javascript" src="Scripts/scriptsAJAX.js"></script>
        <script type="text/javascript" src="Scripts/scriptsCompte.js"></script>
    </head>
    <body>
        <input type="hidden" id="idBackground" name="<%=ConstantesWeb.ATTRIBUT_ID_BACKGROUND%>" value="<%=idBackground%>">
        <div id="bg-select">
            <ol>
                <li><img id="bg0" src="Images/select-bg0.gif" class="imgBackground"/></li>
                <li><img id="bg1" src="Images/select-bg1-red.gif" class="imgBackground"/></li>
                <li><img id="bg2" src="Images/select-bg1-green.gif" class="imgBackground"/></li>
                <li><img id="bg3" src="Images/select-bg1-blue.gif" class="imgBackground"/></li>
                <li><img id="bg4" src="Images/select-bg1-teal.gif" class="imgBackground"/></li>
                <li><img id="bg5" src="Images/select-bg1-gray.gif" class="imgBackground"/></li>
                <li><img id="bg6" src="Images/select-bg2-red.gif" class="imgBackground"/></li>
                <li><img id="bg7" src="Images/select-bg2-green.gif" class="imgBackground"/></li>
                <li><img id="bg8" src="Images/select-bg2-blue.gif" class="imgBackground"/></li>
                <li><img id="bg9" src="Images/select-bg2-teal.gif" class="imgBackground"/></li>
                <li><img id="bg10" src="Images/select-bg2-gray.gif" class="imgBackground"/></li>
                <li><img id="bg11" src="Images/select-bg3-red.gif" class="imgBackground"/></li>
                <li><img id="bg12" src="Images/select-bg3-green.gif" class="imgBackground"/></li>
                <li><img id="bg13" src="Images/select-bg3-blue.gif" class="imgBackground"/></li>
                <li><img id="bg14" src="Images/select-bg3-teal.gif" class="imgBackground"/></li>
                <li><img id="bg15" src="Images/select-bg3-gray.gif" class="imgBackground"/></li>
                <li><img id="bg16" src="Images/select-bg4-red.gif" class="imgBackground"/></li>
                <li><img id="bg17" src="Images/select-bg4-green.gif" class="imgBackground"/></li>
                <li><img id="bg18" src="Images/select-bg4-blue.gif" class="imgBackground"/></li>
                <li><img id="bg19" src="Images/select-bg4-teal.gif" class="imgBackground"/></li>
                <li><img id="bg20" src="Images/select-bg4-gray.gif" class="imgBackground"/></li>
                <li><img id="bg21" src="Images/select-bg5-red.gif" class="imgBackground"/></li>
                <li><img id="bg22" src="Images/select-bg5-green.gif" class="imgBackground"/></li>
                <li><img id="bg23" src="Images/select-bg5-blue.gif" class="imgBackground"/></li>
                <li><img id="bg24" src="Images/select-bg5-teal.gif" class="imgBackground"/></li>
                <li><img id="bg25" src="Images/select-bg5-gray.gif" class="imgBackground"/></li>
            </ol>
        </div>
        <div id="corps">
            <div id="navigation">
                <ol class="nav">
                    <li><a id="hover" class="active" href="./Accueil"><%= strings.getString("NavigationAccueil") %></a></li>
                    <%if(utilisateur != null && utilisateur.getStatut().equals("administrateur")){%>
                        <li><a class="active" href="./GestionCompte"><%= strings.getString("NavigationCompte") %></a></li>
                        <li><a class="active" href="./GestionCours"><%= strings.getString("NavigationCours") %></a></li>
                    <%}%>
                    <li><a class="active" href="aide.jsp"><%=strings.getString("NavigationAide")%></a></li>
                </ol>
            </div>
            <div class="hoverMenu" id="sections">
                <ol>
                    <%for(int i = 0; i < sections.size(); i++){%>
                    <li>
                        <%= sections.get(i).getTitre().concat((sections.get(i).getSousSections().size() > 0)?"   >":"")  %>
                        <% if(sections.get(i).getSousSections().size() != 0){%>
                        <div class="hoverMenu">
                            <ol>
                                <%for(int j = 0; j < sections.get(i).getSousSections().size(); j++){%>
                                <li class="liSousSection" id="<%=j%>">
                                    <form id="formSousSection<%=j%>" action="./SousSection" method="get">
                                        <span>
                                            <%= sections.get(i).getSousSections().get(j).getTitre().concat((sections.get(i).getSousSections().get(j).getDiscussions().size() > 0)?"   >":"")  %>
                                            <input type="hidden" name="<%= ConstantesWeb.PARAM_ID_SOUS_SECTION %>" value="<%= sections.get(i).getSousSections().get(j).getIdSousSection() %>"/>
                                        </span>
                                    </form>
                                    <%if(sections.get(i).getSousSections().get(j).getDiscussions().size() != 0){%>
                                    <div class="hoverMenu">
                                        <ol>
                                            <%for(int k = 0; k < sections.get(i).getSousSections().get(j).getDiscussions().size(); k++){%>
                                            <li class="liDiscussion" id="<%=k%>">
                                                <form id="formDiscussion<%=k%>" action="./Discussion" method="get">
                                                    <span>
                                                        <%= sections.get(i).getSousSections().get(j).getDiscussions().get(k).getTitre() %>
                                                        <input type="hidden" name="<%= ConstantesWeb.PARAM_ID_DISCUSSION %>" value="<%= sections.get(i).getSousSections().get(j).getDiscussions().get(k).getIdDiscussion() %>"/>
                                                    </span>
                                                </form>
                                            </li>
                                            <%}%>
                                        </ol>
                                    </div>
                                    <%}%>
                                </li>  
                                <%}%>
                            </ol>
                        </div>
                        <%}%>
                    </li>  
                    <%}%>
                </ol>
            </div>
            <div id="espCentre">
                <div  id="espInfos" class="alignTop">
                    <table >
                        <thead>
                            <tr>
                                <td colspan="2" class="tailleGrand bold borderBottom">
                                    <%= strings.getString("CompteInformations") %>
                                    <input type="hidden" id="idUtilisateur" value="<%=utilisateur.getIdCompte()%>">
                                </td>
                            </tr>
                        </thead>
                        <tbody>
                            <tr><td colspan="2"><br/></td></tr>
                            <tr>
                                <td class="tailleMoyen bold"><%= strings.getString("CompteNomComplet") %></td>
                                <td class="tailleMoyen paddingLeft"><%=utilisateur.getNomComplet()%></td>
                            </tr>
                            <tr>
                                <td class="tailleMoyen bold"><%= strings.getString("CompteCode") %> </td>
                                <td class="tailleMoyen paddingLeft">
                                    <%if(utilisateur.getCodePermanent() != null && !(utilisateur.getCodePermanent().equals(""))){%>
                                        <%=utilisateur.getCodePermanent()%>
                                    <%}else{%>
                                        <%= strings.getString("CompteNonDefini") %>
                                    <%}%>
                                </td>
                            </tr>
                            <tr>
                                <td class="tailleMoyen bold"><%= strings.getString("CompteSexe") %> </td>
                                <td class="tailleMoyen paddingLeft"><%=utilisateur.getSexe().equals("M") ? strings.getString("CompteMasculin"):strings.getString("CompteFeminin")%></td>
                            </tr>
                            <tr>
                                <td class="tailleMoyen bold"><%= strings.getString("CompteCourriel") %></td>
                                <td class="tailleMoyen paddingLeft">
                                    <%if(utilisateur.getCourriel() != null && !(utilisateur.getCourriel().equals(""))){%>
                                        <%=utilisateur.getCourriel()%>
                                    <%}else{%>
                                        <%= strings.getString("CompteNonDefini") %>
                                    <%}%>
                                </td>
                            </tr>
                            <tr>
                                <td class="tailleMoyen bold"><%= strings.getString("CompteDomaine") %></td>
                                <td class="tailleMoyen paddingLeft"><%=utilisateur.getDomaineEtude()%></td>
                            </tr>
                            <tr>
                                <td class="tailleMoyen bold"><%= strings.getString("CompteStatut") %></td>
                                <td class="tailleMoyen paddingLeft"><%=utilisateur.getStatut()%></td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <form id="formDeconnexion" action="./Deconnection" method="post">
                                        <input type="hidden" name="<%=ConstantesWeb.PARAM_NEXT%>" value="<%=ConstantesWeb.ATTRIBUT_SERV_ACCUEIL%>"/>
                                        <input type="submit" class="fullWidth" value="<%= strings.getString("CompteDeconnection") %>"/>
                                    </form>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                <div id="espMessages" class="alignTop">
                    <form id="formMessages" action="./SupprimerMessInterne" method="post">
                        <table class="fullWidth">
                            <thead>
                                <tr>
                                    <td colspan="4"  class="tailleGrand bold borderBottom"><%= strings.getString("CompteMessagerie") %></td>
                                </tr>
                            </thead>
                            <tbody>
                                <tr id="titresMessage">
                                    <td>
                                        <div class="colCheck"><input type="checkbox" id="chkTout" /></div>
                                        <div class="colMsgLu bold"></div>
                                        <div class="colTitreMsg bold tailleMoyen"><%= strings.getString("CompteTitre") %></div>
                                        <div class="colEnvoyeur bold tailleMoyen"><%= strings.getString("CompteEnvoyeur") %></div>
                                        <div class="colDate bold tailleMoyen"><%= strings.getString("CompteDate") %></div>
                                    </td>
                                </tr>
                                <%for(int i = ((numPage - 1) * 20); i < (numPage * 20 - 1); i++){%>
                                    <%if(i < utilisateur.getMessagesInternes().size()){
                                        MessageInterneBean courant = utilisateur.getMessagesInternes().get(i);%>
                                    <tr class="unMessage taillePetit">
                                        <td>
                                            <div class="colCheck">
                                                <input type="checkbox" class="chkMessage" name ="<%=courant.getIdMessageInterne()%>" id="chk<%=courant.getIdMessageInterne()%>"/>
                                                <input type="hidden" class="messageComplet" id="msg<%=courant.getIdMessageInterne()%>" value="<%=courant.getMessage()%>">
                                            </div>
                                            <div class="colMsgLu">
                                                <%if(courant.getMessageLu() == 'O'){%>
                                                    <img id="msgLu<%=courant.getIdMessageInterne()%>" src="Images/email_open.png"/>
                                                <%}else{%>
                                                    <img id="msgLu<%=courant.getIdMessageInterne()%>" src="Images/email.png"/>
                                                <%}%>
                                            </div>
                                            <div class="colTitreMsg">
                                                <span class="titreMessage pointer" id="<%=courant.getIdMessageInterne()%>" name="titre<%=courant.getIdMessageInterne()%>"><%=courant.getTitre()%></span>
                                            </div>
                                            <div class="colEnvoyeur">
                                                <span class="envoyeurMessage" id="envoyeur<%=courant.getIdMessageInterne()%>">
                                                    <%=courant.getEnvoyeur().getPrenom()%> <%=courant.getEnvoyeur().getNom()%>
                                                </span>
                                            </div>
                                            <div class="colDate">
                                                <span class="dateMessage" id="date<%=courant.getIdMessageInterne()%>"><%=courant.getDateEnvoi()%></span>
                                            </div>
                                        </td>
                                    </tr>
                                    <%}else{%>
                                    <tr class="messageVide">
                                        <td colspan="4">&nbsp;</td>
                                    </tr>
                                    <%}%>
                                <%}%>
                                <tr>
                                    <td class="fullWidth alignRight taillePetit alignMiddle" colspan="4">
                                        Messages <%=numPage * 20 - 19%>-<%=numPage * 20%>&nbsp;&nbsp;
                                        <img id="prevMessages" class="pointer" src="Images/Button-Previous-icon.png"/>&nbsp;
                                        <img id="nextMessages" class="pointer" src="Images/Button-Next-icon.png"/>&nbsp;&nbsp;&nbsp;
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="4" class="alignCenter">
                                        <input type="button" id="btnSupprimerMessages" value="<%= strings.getString("CompteSupprimer") %>"/>&nbsp;
                                        <input type="button" id="btnNouveauMessage" value="<%= strings.getString("CompteNouveau") %>"/>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </form>
                </div>
                <div id="espCours" class="alignTop">
                    <table class="fullWidth">
                        <thead>
                            <tr>
                                <td  colspan="3" class="tailleGrand bold borderBottom"><%= strings.getString("CompteCours") %></td>
                            </tr>
                        </thead>
                        <tbody>
                            <tr id="titreCours">
                                <td class="colTitreCours bold"><%= strings.getString("CompteTitreCours") %></td>
                                <td class="colCode bold"><%= strings.getString("CompteCodeCours") %></td>
                                <td></td>
                            </tr>
                            <%if(!(utilisateur.getCours().isEmpty())){
                                for(CoursBean courant:utilisateur.getCours()){%>
                                <tr class="unCours taillePetit">
                                    <td class="colTitreCours">
                                        <span class="titreCours" id="titre<%=courant.getIdCours()%>" name="titre<%=courant.getTitre()%>"><%=courant.getTitre()%></span>
                                    </td>
                                    <td class="colCode">
                                        <span class="codeCours" id="code<%=courant.getIdCours()%>"><%=courant.getCodeCours()%></span>
                                    </td>
                                    <td>
                                        <form action="./Cours" method="post">
                                            <input type="hidden" class="idCours" id="idCours<%=courant.getIdCours()%>" name="<%=ConstantesWeb.ATTRIBUT_COURS_COURANT%>" value="<%=courant.getIdCours()%>"/>
                                            <input type="submit" value="<%= strings.getString("CompteAcceder") %>">
                                        </form>
                                    </td>
                                </tr>
                                <%}
                            }else{%>
                                <tr>
                                    <td colspan="3" class="alignCenter"><%= strings.getString("CompteAucun") %></td>
                                </tr>
                            <%}%>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>  
        <div id="espLecture" class="popUp">
            <input type="hidden" id="idMessage"/>
            <table class="fullWidth">
                <thead>
                    <tr>
                        <td id="titreLecture" class="fullWidth"></td>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td id="envoyeurLecture"></td>
                    </tr>
                    <tr>
                        <td>
                            <br/>
                            <%= strings.getString("CompteMessageLecture") %>
                            <br/>
                            <textarea id="areaLecture" class="fullWidth" readonly></textarea>
                        </td>
                    </tr>
                    <tr class="fullWidth">
                        <td class="alignCenter"><input type="button" id="btnSupprimerLecture" value="<%= strings.getString("CompteSupprimerLecture") %>"/><input type="button" class="annulerLecture" value="<%= strings.getString("CompteAnnulerLecture") %>"/></td>
                    </tr>
                </tbody>
            </table>
        </div>
        <div id="espEcriture" class="popUp">
          <form id="formEnvoiMessage" action="./EnvoiMessage" method="post">
            <input type="hidden" id="idUser" name="idUser" value="<%=utilisateur.getIdCompte()%>"/>
            <input type="hidden" id="next" name="<%=ConstantesWeb.PARAM_NEXT%>" value="<%=ConstantesWeb.ATTRIBUT_PAGE_COMPTE%>"/>
            <table class="fullWidth">
                <thead>
                    <tr>
                        <td><%= strings.getString("CompteEnvoi") %><span class="pointer annulerEcriture right">[x]</span></td>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td><span id="msgErreurVide" class="taillePetit elemCache"><em><%= strings.getString("CompteRemplir") %></em></span>&nbsp;</td>
                    </tr>
                    <tr>
                        <td>
                            <br/>
                            <%= strings.getString("CompteDestinataire") %> <input id="btnDestinataires" type="button" class="pointer" value="<%= strings.getString("CompteChercheDest") %>"/><br/>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div id="espDestEnvoi" class="taillePetit">
                                <ul id="destinataires">
                                </ul>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td><%= strings.getString("CompteTitreEnvoi") %> <input id="titreEcriture" name="titre" type="text" class="fullWidth noSubmitEnter" maxlength="50"/></td>
                    </tr>
                    <tr>
                        <td class="taillePetit grisPale alignRight">
                            <span id="compteurTitre" class="alignRight">0</span>
                            <span class="alignRight">/50 <%= strings.getString("CompteCaractere") %></span>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <%= strings.getString("CompteMessageEnvoi") %>
                            <br/>
                            <textarea id="areaEcriture" name="message" maxlength="500"></textarea>
                        </td>
                    </tr>
                    <tr>
                        <td class="taillePetit grisPale alignRight">
                            <span id="compteurMessage">0</span>
                            <span>/500 <%= strings.getString("CompteCaractere") %></span>
                        </td>
                    </tr>
                    <tr class="fullWidth">
                        <td class="alignCenter">
                            <input type="button" id="btnEnvoyer" value="<%= strings.getString("CompteEnvoyer") %>" class="pointer"/>
                            <input type="button" class="annulerEcriture pointer" value="<%= strings.getString("CompteAnnulerEnvoi") %>"/>
                        </td>
                    </tr>
                </tbody>
            </table>
          </form>
        </div>
        <div id="espRecherche" class="popUp">
            <table class="fullWidth fullHeight">
                <thead>
                    <tr>
                        <td colspan ="2"><%= strings.getString("CompteRechercheDest") %>  <span class="pointer annulerRecherche right">[x]</span></td>
                    </tr>
                </thead>
                <tbody class="taillePetit">
                    <tr>
                        <td>
                            <input id="txtRecherche" type="text">
                            Statut :
                            <select id="statutRecherche" name="statut">
                                <%for(Map.Entry<Integer,String> statut:statuts.entrySet()){%>
                                <option value="<%=statut.getValue()%>"><%=statut.getValue()%></option>
                                <%}%>
                            </select>
                            <input id="btnRechercher" type="button" value="<%= strings.getString("CompteRechercher") %>"/>
                        </td>
                    </tr>
                    <tr>
                        <td  id="espListRes" class="alignTop">
                            <span class="bold taillePetit alignCenter"><%= strings.getString("CompteResultatRecherche") %></span><br/>
                            <ul id="resultatsRecherche" class="noBulletList"></ul>
                        </td>
                        <td id="espListChoix" class="borderLeft alignTop">
                            <span class="bold taillePetit alignCenter"><%= strings.getString("CompteListeDest") %></span><br/>
                            <ul id="choixRecherche" class="noBulletList"></ul>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2" class="fullWidth alignCenter">
                            <input id="accepterDestinataires" type="button" value="<%= strings.getString("CompteAccepterSelect") %>"/>
                            <input class="annulerRecherche" type="button" value="<%= strings.getString("CompteAnnulerSelect") %>"/>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>                                        
        <div id="espDisable" class="disable"></div>    
        <div id="espDisable2" class="disable"></div>    
        <form id="formChangementPage" action="./ChangementPage" method="post">
            <input type="hidden" name="<%=ConstantesWeb.PARAM_NEXT%>" value="<%=ConstantesWeb.ATTRIBUT_PAGE_COMPTE%>"/>
            <input type="hidden" id="numPage" name="<%=ConstantesWeb.PARAM_NUM_PAGE%>" value="<%=numPage%>"/>
            <input type="hidden" id="totMessages" value="<%=utilisateur.getMessagesInternes().size()%>"/>
        </form>
    </body>
</html>
